/** Sopaco - (c) Sopaco Advanced Technique Support */
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var tslib_1 = require('tslib');
var React = require('react');
var React__default = _interopDefault(React);
var mobxReact = require('mobx-react');
var reactApmApi = require('react-apm-api');
var reactApmCore = require('react-apm-core');
var reactApmPlugins = require('react-apm-plugins');

function assemble(Comp, contextCreator, convert) {
    return /** @class */ (function (_super) {
        tslib_1.__extends(MobxComponent, _super);
        function MobxComponent(props) {
            var _this = _super.call(this, props) || this;
            _this.state = { params: null };
            var params = convert ? convert(props) : props.params;
            _this.contexture = contextCreator(params);
            return _this;
        }
        MobxComponent.getDerivedStateFromProps = function (nextProps, prevState) {
            var params = convert ? convert(nextProps) : {};
            return { params: params };
        };
        MobxComponent.prototype.render = function () {
            var _a = this, contexture = _a.contexture, state = _a.state;
            return (React__default.createElement(mobxReact.Provider, { context: contexture },
                React__default.createElement(Comp, tslib_1.__assign({}, this.props, { context: contexture, params: state.params }))));
        };
        MobxComponent.prototype.componentDidMount = function () {
            var contexture = this.contexture;
            return contexture.componentDidMount && contexture.componentDidMount();
        };
        MobxComponent.prototype.getSnapshotBeforeUpdate = function (prevProps, prevState) {
            var contexture = this.contexture;
            return contexture.getSnapshotBeforeUpdate && contexture.getSnapshotBeforeUpdate(prevProps, prevState);
        };
        MobxComponent.prototype.componentDidUpdate = function () {
            var contexture = this.contexture;
            return contexture.componentDidUpdate && contexture.componentDidUpdate();
        };
        MobxComponent.prototype.componentWillUnmount = function () {
            var contexture = this.contexture;
            return contexture.componentWillUnmount && contexture.componentWillUnmount();
        };
        MobxComponent.prototype.componentDidCatch = function (error, info) {
            var contexture = this.contexture;
            return contexture.componentDidCatch && contexture.componentDidCatch(error, info);
        };
        return MobxComponent;
    }(React.Component));
}

var Context = /** @class */ (function () {
    function Context(props) {
        this.props = props;
    }
    return Context;
}());



var index = Object.freeze({
	assemble: assemble,
	Context: Context
});

function launchDefaults() {
    return Promise.all([
        reactApmPlugins.CpuPlugin,
        reactApmPlugins.FpsPlugin,
        reactApmPlugins.GcpPlugin,
        reactApmPlugins.MemoryPlugin,
        reactApmPlugins.MrtPlugin,
        reactApmPlugins.TrafficPlugin,
        reactApmPlugins.ScuPlugin,
        reactApmPlugins.BootPlugin,
        reactApmPlugins.JSEventLoopPlugin,
        reactApmPlugins.MethodTracePlugin
    ].map(function (PluginType) {
        var plugin = new PluginType();
        var recorder = new reactApmCore.MemoryRecorder();
        var outlet = new reactApmCore.ConsoleOutlet();
        var profiler = new reactApmCore.Profiler(plugin, recorder, outlet);
        return profiler.start({ boot: reactApmApi.Schedule.Erupt, sampler: {} });
    }));
}


var index$1 = Object.freeze({
	launchDefaults: launchDefaults
});

exports.mobx = index;
exports.performance = index$1;
